#include "StdAfx.h"
#include "Balloon.h"

CBalloon::CBalloon(NOTIFYICONDATA* nid) {
	this->nid = nid;
}
CBalloon::CBalloon(HWND hWnd, HICON hIcon, TCHAR* szTitle, TCHAR* szTip, UINT uCallbackMsg)
{
	nid = new NOTIFYICONDATA;
	ZeroMemory(nid, sizeof(NOTIFYICONDATA));
	nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
	nid->dwInfoFlags = NIIF_INFO;
	nid->cbSize = NOTIFYICONDATA_V2_SIZE;
	nid->hWnd = hWnd;
	nid->uID = 0;
	nid->uVersion = NOTIFYICON_VERSION;
	nid->uCallbackMessage = uCallbackMsg;
	nid->hIcon = hIcon;
	wcscpy_s(nid->szTip, szTip);
	wcscpy_s(nid->szInfoTitle, szTip);	

	Shell_NotifyIcon(NIM_ADD, nid);
}

CBalloon::~CBalloon(void)
{
	Shell_NotifyIcon(NIM_DELETE, nid);
}

void CBalloon::Show(LPCWSTR szText, DWORD dwInfoFlag) {	
	nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
	wcscpy_s(nid->szInfo, szText);	
	nid->dwInfoFlags = dwInfoFlag;

	Shell_NotifyIcon(NIM_MODIFY, nid);
}

void CBalloon::Notify(LPCWSTR szText) {	
	Show(szText, NIIF_INFO);
}

void CBalloon::Error(LPCWSTR szText) {
	Show(szText, NIIF_ERROR);
}